home *** CD-ROM | disk | FTP | other *** search
/ SuperHack / SuperHack CD.bin / CODING / GRAPHICS / COMMON.ZIP / PALSET.C < prev    next >
Encoding:
C/C++ Source or Header  |  1995-05-09  |  2.3 KB  |  112 lines

  1. /*
  2.  
  3. Copyright 1995 Alec Russell, ALL rights reserved.
  4. Permission granted by Alec Russell to use this code as anyone wishes.
  5.  
  6. */
  7.  
  8. #define INPUT_STATUS_1  03dah   //Input Status 1 register
  9. #define INPUT_STATUS_0  03dah   //Input status 0 register
  10.  
  11.  
  12. /* set the VGA palette, p points to valid palette of 768 bytes
  13.    of rgb triples
  14.  
  15.    works in all xmodes too - faster than the one in xlib
  16. */
  17. void setvgapalette(char *p)
  18. {
  19.  
  20.    /* wait for vert sync */
  21.    asm   {
  22.          mov     dx,INPUT_STATUS_1
  23.          }
  24. WaitVS:
  25.    asm   {
  26.          in      al,dx
  27.          test    al,08h
  28.          jz      WaitVS  /* vertical sync is active high (1 = active) */
  29.          }
  30.  
  31.    asm   {
  32.          .386
  33.  
  34. /*       this sets the default palette register mask, don't need to do
  35.          this unless it gets changed
  36.  
  37.          mov   dx, 03c6h
  38.          mov   al, 0ffh
  39.          out   dx, al
  40. */
  41.  
  42.          /* set palette, taking advantage of the auto-increment feature */
  43.          xor   al, al
  44.          mov   dx, 03c8h
  45.          out   dx, al
  46.          mov   cx, 768
  47.          mov   si, p
  48.          mov   dx, 03c9h
  49.          rep   outsb
  50.          }
  51. }
  52.  
  53.  
  54.  
  55. /* ---------------------- setvga_part_palette() ---------- March 28,1993 */
  56. void setvga_part_palette(char *p, short start, short num)
  57. {
  58.  
  59.    p+=start*3;
  60.    num*=3;
  61.  
  62.    /* wait for vert sync */
  63.    asm   {
  64.          mov     dx,INPUT_STATUS_1
  65.          }
  66. WaitVS:
  67.    asm   {
  68.          in      al,dx
  69.          test    al,08h
  70.          jz      WaitVS  /* vertical sync is active high (1 = active) */
  71.          }
  72.  
  73.    asm   {
  74.          .386
  75.  
  76.          /* set partial palette */
  77.          mov   ax, start
  78.          mov   dx, 03c8h
  79.          out   dx, al
  80.          mov   cx, num
  81.          mov   si, p
  82.          mov   dx, 03c9h
  83.          rep   outsb
  84.          }
  85. }
  86.  
  87.  
  88.  
  89. /* do colour cycling, starting with color start, num sequential colors */
  90. /* ---------------------- cycle_palette() ---------------- March 28,1993 */
  91. void cycle_palette(short start, short num)
  92. {
  93.    BYTE t[3];
  94.    short x1, x2, len;
  95.  
  96.    num--;
  97.    len=num*3;
  98.  
  99.  
  100.    x1=start*3;
  101.    x2=len + x1;
  102.  
  103.    /* cycle the palette  */
  104.    memcpy(t, palette+x1, 3);
  105.    memmove(palette+x1, palette+x1+3, len);
  106.    memcpy(palette+x2, t, 3);
  107.  
  108.    /* set new pallette */
  109.    num++;
  110.    setvga_part_palette(palette, start, num);
  111. }
  112.